package com.th.service.impl;

import com.th.common.utils.SseEmitterUtil;
import com.th.service.SSEService;
import com.th.service.UsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

/**
 * @author ErrorRua
 * @date 2023/06/25
 * @description:
 */
@Service
public class SSEServiceImpl implements SSEService {

    @Autowired
    private UsUserService usUserService;

    @Override
    public void sendMessage(Long userId, String message) {
        SseEmitterUtil.sendMessage(userId, message);
    }

    @Override
    public void disconnect(Long userId) {
        SseEmitterUtil.removeUser(userId);
    }

    @Override
    public SseEmitter connect() {
        Long userId = usUserService.getCurrentUserId();
        return SseEmitterUtil.connect(userId);
    }
}
